<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>社医堂</title>
<link rel="stylesheet" type="text/css" href="../../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/iconfont.css" />
</head>
<body>


<style type="text/css">
	.aui-list-item.wechat-top {
		background-color: #f3f3f7;
	}
	.aui-list .wechat-avatar {
		width:3rem;
	}
	.wechat-avatar .aui-row-padded {
		background-color: #dddee0;
		padding: 0.1rem;
		border-radius: 0.2rem;
		margin-left: -0.05rem;
		margin-right: -0.05rem;
	}
	.wechat-avatar .aui-row-padded [class*=aui-col-xs-] {
		padding: 0.05rem;
	}
	.wechat-avatar,
	.wechat-avatar > img {
		border-radius:0.2rem;
	}
</style>


<div class="aui-content aui-margin-b-15">
	<ul class="aui-list aui-media-list">


		<span id="list" style="width:100%;"></span>


	</ul>
</div>


<script src="../../../script/hui.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/hui-tab.js" type="text/javascript"></script>
<script src="../../../script/api.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../script/stm.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
apiready = function() {
    api.setRefreshHeaderInfo({
        visible : true,
        bgColor : 'rgba(0,0,0,0)',
        textColor : '#666',
        textDown : '下拉刷新',
        textUp : '释放刷新'
    }, function(ret, err) {
        api.refreshHeaderLoadDone();
    });

	list()
	$api.setStorage('total',0);
};




function list(){
	api.showProgress({title:'加载中...',text: '先喝杯茶...'});
	console.log($api.getStorage('hospid'))

	api.ajax({
		url: $api.getStorage('geturl')+'&c=ajaxmember&a=patientlist',
		method: 'post',
		data: {
			values: { 
				userid: $api.getStorage('userid'),
				docid : $api.getStorage('docid'),
				hospid: $api.getStorage('hospid')
			}
		}
	},function(ret, err){

		//console.log(JSON.stringify(ret))
		if (ret.status==1) {			
				
			var list = '';
			list += '<li class="aui-list-item aui-list-item-middle">';
					list += '<div class="aui-media-list-item-inner">';
						list += '<div class="aui-list-item-media wechat-avatar" onclick="toDetails(\'./\',\'chat_qun\','+$api.getStorage('docid')+',\'\')">';
							list += '<div class="aui-badge">0</div><img src="../../../image/qun.png" /></div>';
							list += '<div class="aui-list-item-inner">';
								list += '<div class="aui-list-item-text">';
									list += '<div class="aui-list-item-title" onclick="toDetails(\'./\',\'chat_qun\','+$api.getStorage('docid')+',\'\')">群聊</div>';
							list += '</div>';
							list += '<div class="aui-list-item-text aui-font-size-12" onclick="toDetails(\'./\',\'chat_qun\','+$api.getStorage('docid')+',\'\')">群聊内容</div>';
						list += '</div>';
					list += '</div>';
				list += '</li>';
			for(i=0;i<ret.data.length;i++){

				var thumb = ret.data[i].avatar
				if(thumb==''){
					thumb = '../../../image/avatar.png'
				}else{
					if(thumb.substring(0,7)!='http://' && thumb.substring(0,8)!='https://' && thumb.substring(0,7)!='/storage'){
						thumb = $api.getStorage('weburl')+thumb
					}else{
						thumb = thumb
					}					
				}

				list += '<li class="aui-list-item aui-list-item-middle">';
					list += '<div class="aui-media-list-item-inner">';
						list += '<div class="aui-list-item-media wechat-avatar">';
							if(ret.data[i].num>0){
								list += '<div class="aui-badge" id="num_'+ret.data[i].userid+'">'+ret.data[i].num+'</div>';
							}
							list += '<img onclick=toDetails(\'../doctor/\',\'chat\','+ret.data[i].userid+',\"'+ret.data[i].dname+'\") style="border-radius:5px;border:solid #ccc 1px;" src="'+thumb+'" /></div>';
							list += '<div class="aui-list-item-inner">';
								list += '<div class="aui-list-item-text">';
									list += '<div class="aui-list-item-title" onclick=toDetails(\'../doctor/\',\'chat\','+ret.data[i].userid+',\"'+ret.data[i].dname+'\")>'+ret.data[i].name+'</div>';
							list += '</div>';
							list += '<div class="aui-list-item-text aui-font-size-12">'+ret.data[i].content+'</div>';
						list += '</div>';
					list += '</div>';
				list += '</li>';
					
			}
			$api.html($api.byId("list"),list);
			//$api.append($api.byId("list"),list);

		
		} else {
			alert( JSON.stringify( err ) );
		}
	});

	
	api.hideProgress();
}




function getonread(){

	api.ajax({
		url: $api.getStorage('geturl')+'&c=ajaxmember&a=getnoread',
		method: 'post',
		data: {
			values: { 
				userid: $api.getStorage('userid'),
				docid : $api.getStorage('docid'),
				hospid: $api.getStorage('hospid')
			}
		}
	},function(ret, err){

		if (ret.status==1) {
			var audioStreamer = api.require('audioStreamer');
			//alert($api.getStorage('total')+"="+ret.total)
			if(ret.total>0 && $api.getStorage('total')!=ret.total){
				$api.setStorage('total',ret.total);
				audioStreamer.openPlayer({
					path: $api.getStorage('weburl')+'uploadfiles/2.mp3',
				}, function(ret) {
					if (ret.status) {
						//api.alert({ msg: JSON.stringify(ret) });
					}
				});
			}else{
				//$api.setStorage('total',0);
				audioStreamer.stop();
			}
			for(i=0;i<ret.data.length;i++){
				var docid = ret.data[i].docid				
				$api.html($api.byId("num_"+docid),ret.data[i].num);					
			}		
		} else {
			alert( JSON.stringify( err ) );
		}
	});

}
setInterval("getonread()",10000)
</script>

</body>
</html>